package com.lagou.rpc.consumer;

import com.lagou.rpc.consumer.client.RpcClient;
import com.lagou.rpc.consumer.proxy.RpcClientProxy;
import com.lagou.rpc.consumer.task.ReportToZkTask;
import com.lagou.rpc.util.ZkUtil;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.recipes.cache.ChildData;
import org.apache.curator.framework.recipes.cache.TreeCache;
import org.apache.curator.framework.recipes.cache.TreeCacheEvent;
import org.apache.curator.framework.recipes.cache.TreeCacheListener;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * 测试类
 */
@SpringBootApplication
public class ClientBootStrap extends SpringBootServletInitializer implements CommandLineRunner {

    public static void main(String[] args) {
        /*IUserService userService = (IUserService) RpcClientProxy.createProxy(IUserService.class);
        User user = userService.getById(1);
        System.out.println(user);*/

        SpringApplication.run(ClientBootStrap.class, args);
    }

    @Override
    public void run(String... args) throws Exception {

        RpcClientProxy rpcClientProxy = new RpcClientProxy();

        rpcClientProxy.watchService();

        ScheduledExecutorService executorService = Executors.newScheduledThreadPool(5);


        executorService.scheduleWithFixedDelay(new ReportToZkTask(),5,5, TimeUnit.SECONDS);

    }
}
